package com.heihei.imgpreview;

import com.heihei.util.FileUtilF;
import com.heihei.util.ImgUtil;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ImgTest {
    public static void main(String[] args) throws IOException {
//        start();
        testWriteImg();
    }

    /**
     * 开始
     */
    private static void start() {
        File parentFile = new File("C:\\Users\\12851\\Desktop\\测试图片");
        List<File> fileImgList = getAllImgList(parentFile);
    }

    /**
     * 方法描述: 测试写图片
     *
     * @param
     * @Return
     * @throws
     * @author duanhengfei
     * @date 2021年01月30日 13:42:10
     */
    public static void testWriteImg() throws IOException {
        File file = new File("C:\\Users\\12851\\Desktop\\表情包\\01.jpg");
        BufferedImage img01 = ImgUtil.loadImageLocal(file);

        BufferedImage tag = new BufferedImage(1080,1080,BufferedImage.TYPE_INT_RGB);
        Graphics2D graphics = tag.createGraphics();
        //设置颜色为218，223，224
        graphics.setColor(new Color(102,253,255));
        //填充颜色
        graphics.fillRect(0, 0, 1080, 1080);
        graphics.drawImage(img01, 0, 0, img01.getWidth(), img01.getHeight(), null);
        graphics.dispose();
        ImageIO.write(tag, "jpg", new File("C:\\Users\\12851\\Desktop\\表情包\\哈哈哈.jpg"));
    }

    /**
     * 获取所有图片List
     * @return
     * @param parentFile
     */
    private static List<File> getAllImgList(File parentFile) {
        ArrayList<File> imgFileList = new ArrayList<>();
        File[] files = parentFile.listFiles();
        for (File file : files) {
            if(file.isFile() && FileUtilF.isImg(file)) {
                imgFileList.add(file);
            }
        }
        return imgFileList;
    }
}
